#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

string clearStars(string s) {
    vector<int> stk[26];
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] != '*')
        {
            stk[s[i] - 'a'].push_back(i);
            continue;
        }
        for (auto& st : stk)
            if (st.size())
            {
                st.pop_back();
                break;
            }
    }

    vector<int> idx;
    for (auto& st : stk)
        idx.insert(idx.end(), st.begin(), st.end());
    sort(idx.begin(), idx.end());

    string res(idx.size(), 0);
    for (int i = 0; i < idx.size(); i++)
        res[i] = s[idx[i]];
    return res;
}